<template>
	<Layout :class="'bg-white p-2'">
		<Row :class="'m-1'">
			<!-- 			<Button type="error" @click="newUser">新增</Button>
			<Input :class="'w-25 m-2'" v-model="searchKey" placeholder="请输入检索关键字" />
			<Button type="primary" shape="circle" @click="search" icon="ios-search">查询</Button> -->
			<!-- <Col span="4">
			<Button class="m-2" type="error" @click="newUser">新增</Button>
			</Col> -->

			<Col span="4">
			<Input :class="'w-75 m-2'" v-model="searchTrainerName" placeholder="请输入教练姓名" />
			</Col>

			<Col span="4">
			<Input :class="'w-75 m-2'" v-model="searchPhone" placeholder="请输入教练手机号" />
			</Col>

			<Col span="4">
			<Input :class="'w-75 m-2'" v-model="searchIc" placeholder="请输入教练身份证号" />
			</Col>

			<Col span="4">
			<Radio-group v-model="searchSex">
				<Radio label="true">男</Radio>
				<Radio label="false">女</Radio>
			</Radio-group>
			</Col>
			<Col span="4">
			<Button class="m-2" type="primary" shape="circle" @click="search" icon="ios-search">查询</Button>
			</Col>
		</Row>
		<Layout :class="'bg-white'">
			<Table border :class="'m-1'" :columns="tableInfo.columnInfo" :data="tableInfo.data">
				<template slot-scope="{ row, index }" slot="sex">
					<span v-if="row.sex">男</span>
					<span v-else>女</span>
				</template>



				<template slot-scope="{ row, index }" slot="action">
					<Button type="primary" size="small" style="margin-right: 5px"
						@click="show(row.trainerId)">详细</Button>
					<!-- <Button type="error" size="small" @click="remove(row.trainerId)">删除</Button> -->
				</template>
			</Table>
			<Page :class="'m-2 text-right'" :page-size="tableInfo.pageSize" @on-change="pageSearch"
				:total="tableInfo.total" />
		</Layout>
	</Layout>
</template>
<script>
	export default {
		data() {
			return {
				searchTrainerName: "",
				searchPhone: "",
				searchIc: "",
				searchSex: "",
				tableInfo: {
					currentPage: 1,
					total: 0,
					columnInfo: [{
							title: "教练编号",
							key: "trainerId",
							width: 150
						},
						{
							title: "姓名",
							key: "trainerName",
							width: 200
						},
						{
							title: "电话",
							key: "phone",
							width: 150
						},

						{
							title: "身份证",
							key: "ic",
							width: 200
						},
						{
							title: "性别",
							slot: 'sex',
							width: 200
						},
						{
							title: "操作",
							slot: 'action'
						}
					],
					data: []
				}
			}
		},
		methods: {
			init: function() {
				this.$data.tableInfo.currentPage = 0;
				this.search();
			},
			newUser: function() {
				this.$router.push({
					name: "trainer_new"
				});
			},
			show: function(trainerId) {
				this.$router.push({
					name: 'trainer_detail',
					params: {
						trainerId
					}
				});
			},
			update(trainerId) {
				this.$router.push({
					name: "trainer_update",
					params: {
						trainerId
					}
				});
			},
			// remove: function(trainerId) {

			// 	this.message.confirm({
			// 		title: "删除提示",
			// 		content: "即将删除该体训师，确定吗？",
			// 		onOk: () => {
			// 			this.http.delete({
			// 				url: "/trainer/info",
			// 				param: {
			// 					trainerId
			// 				}
			// 			}).then(data => {

			// 				this.search();
			// 			});
			// 		},
			// 		onCancel: () => {
			// 			this.message.info('操作已取消');
			// 		}
			// 	});
			// },
			search: function() {
				let self = this;
				this.http.get({
					url: "/trainer/list",
					param: {
						currentPage: this.$data.tableInfo.currentPage,
						trainerName: this.$data.searchTrainerName,
						phone: this.$data.searchPhone,
						ic: this.$data.searchIc,
						sex: this.$data.searchSex,
					}
				}).then(data => {
					self.$data.tableInfo.currentPage = data.current;
					self.$data.tableInfo.total = data.total;
					self.$data.tableInfo.pageSize = data.size;
					self.$data.tableInfo.data = data.records;


				});
			},
			pageSearch: function(changedPage) {
				this.$data.tableInfo.currentPage = changedPage;
				this.search();
			}
		},
		created: function() {
			this.init();
		}

	}
</script>

<style>

</style>
